ShowPopupAsync will now correctly return once the popup is closed under heavy garbage collection#2756
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug where ShowPopupAsync would not return correctly under heavy garbage collection by updating the popup closing mechanism and adding tests to simulate GC pressure.
- Replaced the WeakEventManager based PopupClosed event with a standard event invocation.
- Introduced a new popup subclass (GarbageCollectionHeavySelfClosingPopup) to simulate heavy GC scenarios during popup closure.
- Updated tests to include explicit GC.Collect calls around CloseAsync to validate the fix.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | Replaced weak event manager with a standard event for PopupClosed |
| src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs | Added GC.Collect calls and a new popup subclass for heavy GC testing |
| src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs | Added a test to verify that ShowPopupAsync returns the correct result under heavy GC |
| src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs | Registered the new GarbageCollectionHeavySelfClosingPopup service |
Comments suppressed due to low confidence (3)
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:65
- Replacing the WeakEventManager with a standard event might lead to memory retention if subscribers are not properly unsubscribed. Ensure that consumers of PopupClosed unsubscribe when appropriate.
public event EventHandler<IPopupResult>? PopupClosed;
src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs:558
- Consider adding a comment explaining the intent behind invoking GC.Collect here, to improve clarity for future maintainers of this test.
GC.Collect();
src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs:560
- Consider adding a comment explaining the intent behind invoking GC.Collect here, to improve clarity for future maintainers of this test.
GC.Collect();
|
This will likely conflict with #2749 but I am happy to deal with that |
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Thanks Shaun! Good catch!
|
Full credit to @mfeingol for the investigation into this. It was easy once he worked out that it was garbage collection related |
Description of Change
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information